/* license set forth in the LICENSE file included with this software,      */
/* and also available at http://www.link.cs.cmu.edu/link/license.html      */
/* This license allows free redistribution and use in source and binary    */
/* forms, with or without modification, subject to certain conditions.     */
/*                                                                         */
/***************************************************************************/

 /****************************************************************************
 *
 *   This is a simple example of the link parser API.  It similates most of
 *   the functionality of the original link grammar parser, allowing sentences
 *   to be typed in either interactively or in "batch" mode (if -batch is
 *   specified on the command line, and stdin is redirected to a file).
 *   The program:
 *     Opens up a dictionary
 *     Iterates:
 *        1. Reads from stdin to get an input string to parse
 *        2. Tokenizes the string to form a Sentence
 *        3. Tries to parse it with cost 0
 *        4. Tries to parse with increasing cost
 *     When a parse is found:
 *        1. Extracts each Linkage
 *        2. Passes it to process_some_linkages()
 *        3. Deletes linkage
 *     After parsing each Sentence is deleted by making a call to
 *     sentence_delete.
 *
 ****************************************************************************/

#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>

/* Used for terminal resizing */
#ifndef _WIN32
#include <termios.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#endif

#include "link-includes.h"
#include "structures.h"
#include "error.h"
#include "command-line.h"
#include "expand.h"

string toJSON(Linkage l)
{
string res = "";

return res;
}

int main(int argc, char * argv[])
{
	Dictionary    dict;
    Parse_Options opts;
	Sentence      sent;
    Linkage       linkage;
    char *        diagram;
    int           num_linkages;
	const char *  input_string = "I jumped over the fence";
	//std::string res = "nothing";

	fprintf(stderr,"here %s",input_string);
	fflush(stderr);
	opts  = parse_options_create();
    dict  = dictionary_create("C:\\Users\\IBM_ADMIN\\link-grammar\\data\\en\\4.0.dict", "C:\\Users\\IBM_ADMIN\\link-grammar\\data\\en\\4.0.knowledge", NULL, "C:\\Users\\IBM_ADMIN\\link-grammar\\data\\en\\4.0.affix");
	sent = sentence_create(input_string, dict);
	num_linkages = sentence_parse(sent, opts);
	fprintf(stderr,"here");
	if (num_linkages > 0) {
		
		linkage = linkage_create(0, sent, opts);
		//diagram = linkage_print_diagram(linkage);
		printf("%s\n", diagram = linkage_print_diagram(linkage));
		//delete(diagram);
		linkage_delete(linkage);
		sentence_delete(sent);
    }


	parse_options_delete(opts);
	dictionary_delete(dict);

	printf ("Bye.\n");
	return 0;
}
